#!/bin/bash

source $DRAW_INI
source $DRAW_CFG

# removed -bm EMPIRICAL for more recent GATK
# 2011-11-11: added --read_filter MappingQuality for -mmq

#optional dbsnp; no dbSNP for celegans
if [ -z $SNPDB ];then
  DTAG=""
else
  DTAG="-D $SNPDB"
fi

#optional $TARGET, i.e. WGS if -z 
if [ -z $TARGET ];then
  LTAG=""
else
  LTAG="-L $TARGET"
fi

java -Xmx4g -jar $GATK \
 -l INFO \
 -R $REF_FASTA \
 -T UnifiedGenotyper \
 -mbq $2 \
 --read_filter MappingQuality -mmq $3 \
 --read_filter DuplicateRead \
 --genotype_likelihoods_model BOTH \
 -nt $GATK_THREADS \
 $DTAG \
 $LTAG \
 -I $4.bam \
 -o ${1}.vcf

EXITSTATUS=$?

#if [ ! -s "${1}.vcf" ]; then exit 100;fi;
#if [ $(grep -cv "^#" "${1}.vcf") -eq "0" ]

if [ ! -s "${1}.vcf.idx" ]
 then
  echo "vcf incomplete!"
  exit 100;
fi

# java -Xmx4g -jar $GATK \
#  -l INFO \
#  -R $REF_FASTA \
#  -T SelectVariants \
#  -selectType INDEL \
#  --variant ${3}/s_${1}${2}_mbq_${4}_mmq_${5}.vcf \
#  -o ${3}/s_${1}${2}_mbq_${4}_mmq_${5}_indel.vcf


if [ $EXITSTATUS -ne 0 ];then exit $EXITSTATUS;fi

